//
//  PassengerFullInfoView.swift
//  JiaoZiTaxi
//
//  Created by Hu Gang on 2022/10/17.
//

import SwiftUI

//
//  UserInfoView.swift
//  JiaoZiTaxi
//
//  Created by Hu Gang on 2022/10/10.
//

import SwiftUI

struct PassengerFullInfoView: View {
  @ObservedObject var passenger : PassengerInput
  @Environment(\.dismiss) var dismiss
//  @Binding var showSheet : Bool

  var body: some View {
    ZStack {
//      Image("background")
        NavigationView {
            VStack {
//                Text("为了让司机快捷联系到您，请提供以下信息")
//                    .foregroundColor(.red)
//                    .font(.system(size: 14))
//                    .padding()
                
                TextField("填写老挝手机", text: $passenger.laosMobile)
                    .foregroundColor(.accentColor)
                    .keyboardType(.phonePad)
                    .padding()
                    .overlay(content: {
                        RoundedRectangle(cornerRadius: 5)
                            .stroke(.gray,lineWidth: 1)
                    })
                
                TextField("填写微信号码", text: $passenger.wechatNo)
                    .foregroundColor(.accentColor)
                    .padding()
                    .overlay(content: {
                        RoundedRectangle(cornerRadius: 5)
                            .stroke(.gray,lineWidth: 1)
                    })
                
                //        TextField("填写中国手机号码", text: $passenger.mobile)
                //          .foregroundColor(.accentColor)
                //          .keyboardType(.phonePad)
                //          .padding()
                //          .overlay(content: {
                //            RoundedRectangle(cornerRadius: 5)
                //              .stroke(.gray,lineWidth: 1)
                //          })
                //
                //        TextField("填写姓名或昵称", text: $passenger.name)
                //          .foregroundColor(.accentColor)
                //          .padding()
                //          .overlay(content: {
                //            RoundedRectangle(cornerRadius: 5)
                //              .stroke(.gray,lineWidth: 1)
                //          })
                //
                //        Picker("性别",selection: $passenger.gender) {
                //          Text("先生").tag(true)
                //          Text("女士").tag(false)
                //        }
                //          .frame(height:30)
                //          .pickerStyle(.segmented)
                //          .padding()
                
                Button {
                    print("save")
                    var info = ViewModel.shared.passenger
                    info.laosMobile = passenger.laosMobile
                    info.wechatNo = passenger.wechatNo
                    info.mobile = passenger.mobile
                    info.isMale = passenger.gender
                    info.name = passenger.name
                    
                    passenger.save(info: info)
                    
                    //          self.showSheet = false
                    dismiss()
                } label: {
                    Text("保存")
                        .padding()
                        .foregroundColor(.white)
                        .frame(width: 300, height: 50)
                        .background(
                            RoundedRectangle(cornerRadius: 10.0)
                                .fill(Color.themeColor())
                            
                        )
                        .padding()
                }
                //        .onChange(of: showSheet) { newValue in
                //          showSheet = newValue
                //        }
                Spacer()
            }
//            .frame(width: 320,height: 450)
            .padding()
            .background(.white)
            .cornerRadius(10)
//            .shadow(radius: 10)
        }.navigationBarBackButtonHidden(true) // 隐藏默认返回按钮
            .navigationBarItems(leading: backButton) // 添加自定义返回按钮
            .navigationTitle("乘客信息")
    }

  }
    var backButton: some View {
        Button(action: {
            dismiss()
        }) {
            HStack {
                Image(systemName: "chevron.backward").foregroundColor(Color(hex: 0x333333))
            }
        }
    }
}

//struct PassengerFullInfoView_Previews: PreviewProvider {
//    static var previews: some View {
//      PassengerFullInfoView(passenger: PassengerInput(), showSheet: .constant(true))
//    }
//}
